package com.example.web03homework.dao;

import com.example.web03homework.Mapper.CategoryMapper;
import com.example.web03homework.pojo.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class CategoryDao {
    
    @Autowired
    private CategoryMapper categoryMapper;
    
    public List<Category> getAllCategories() {
        return categoryMapper.getAllCategories();
    }
    
    public List<Category> getPrimaryCategories() {
        return categoryMapper.getPrimaryCategories();
    }
    
    public List<Category> getChildrenByParentId(Integer parentId) {
        return categoryMapper.getChildrenByParentId(parentId);
    }
    
    public Category getById(Integer id) {
        return categoryMapper.getById(id);
    }
    
    public void insert(Category category) {
        categoryMapper.insert(category);
    }
    
    public void update(Category category) {
        categoryMapper.update(category);
    }
    
    public void deleteById(Integer id) {
        categoryMapper.deleteById(id);
    }
    
    public void deleteByParentId(Integer parentId) {
        categoryMapper.deleteByParentId(parentId);
    }
    
    public int countBooksByCategoryId(Integer categoryId) {
        return categoryMapper.countBooksByCategoryId(categoryId);
    }
    
    public int countBooksByCategoryIdWithChildren(Integer parentId) {
        return categoryMapper.countBooksByCategoryIdWithChildren(parentId);
    }
}
